use std::collections::HashMap;

struct Solution {}

fn main() {}

impl Solution {
    pub fn first_uniq_char(s: String) -> i32 {
        let mut map: HashMap<char, i32> = HashMap::new();
        for x in s.chars() {
            if !map.contains_key(&x) {
                map.insert(x.clone(), 1);
                continue;
            }
            map.insert(x.clone(), map.get(&x).unwrap() + 1);
        }

        let v: Vec<char> =  s.chars().into_iter().collect::<Vec<_>>();
        for idx in 0..s.len() {
            if *map.get(&(v[idx])).unwrap() == 1 {
                return idx as i32;
            }
        }
        -1
    }
}